/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cse308.entities;

import cse308.GeneralEntity;
import cse308.helper_classes.GeneralTest;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Aaron
 */
@Entity
@Table(catalog = "nchorn", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Courseoffering.findAll", query = "SELECT c FROM Courseoffering c"),
    @NamedQuery(name = "Courseoffering.findByCourse", query = "SELECT c FROM Courseoffering c WHERE c.courseofferingPK.course = :course"),
    @NamedQuery(name = "Courseoffering.findBySection", query = "SELECT c FROM Courseoffering c WHERE c.courseofferingPK.section = :section"),
    @NamedQuery(name = "Courseoffering.findBySemester", query = "SELECT c FROM Courseoffering c WHERE c.courseofferingPK.semester = :semester"),
    @NamedQuery(name = "Courseoffering.findByInstructor", query = "SELECT c FROM Courseoffering c WHERE c.instructor = :instructor"),
    @NamedQuery(name = "Courseoffering.findByCourseOutcomeAttainmentTarget", query = "SELECT c FROM Courseoffering c WHERE c.courseOutcomeAttainmentTarget = :courseOutcomeAttainmentTarget"),
    @NamedQuery(name = "Courseoffering.findByCoursecoordinator", query = "SELECT c FROM Courseoffering c WHERE c.coursecoordinator = :coursecoordinator"),
    @NamedQuery(name = "Courseoffering.findByAltcoursecoordinator", query = "SELECT c FROM Courseoffering c WHERE c.altcoursecoordinator = :altcoursecoordinator")})
public class Courseoffering implements Serializable, GeneralEntity {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CourseofferingPK courseofferingPK;
    @Size(max = 20)
    @Column(length = 20)
    private String instructor;
    @Lob
    private byte[] syllabus;
    @Lob
    private byte[] schedule;
    @Lob
    private byte[] lectureNotes;
    @Size(max = 45)
    @Column(length = 45)
    private String courseOutcomeAttainmentTarget;
    @Lob
    private byte[] endOfSemesterReport;
    @Lob
    private byte[] courseCoordinatorReport;
    @Lob
    private byte[] cICReport;
    @Size(max = 20)
    @Column(length = 20)
    private String coursecoordinator;
    @Size(max = 20)
    @Column(length = 20)
    private String altcoursecoordinator;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "courseoffering")
    private Collection<Courseoutcomedirectassessment> courseoutcomedirectassessmentCollection;
  
    @JoinColumn(name = "course", referencedColumnName = "identifier", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Courseinfo courseinfo;
    @OneToMany(mappedBy = "courseoffering")
    private Collection<Assignment> assignmentCollection;
    @OneToMany(mappedBy = "courseoffering")
    private Collection<Courseoutcomesurveyresults> courseoutcomesurveyresultsCollection;
    public Courseoffering() {
        assignmentCollection = new ArrayList();
        courseoutcomesurveyresultsCollection = new ArrayList();
        courseoutcomedirectassessmentCollection = new ArrayList();
    }

    public Courseoffering(CourseofferingPK courseofferingPK) {
        this.courseofferingPK = courseofferingPK;
        assignmentCollection = new ArrayList();
        courseoutcomesurveyresultsCollection = new ArrayList();
        courseoutcomedirectassessmentCollection = new ArrayList();
        
    }

    public Courseoffering(String course, int section, String semester) {
        this.courseofferingPK = new CourseofferingPK(course, section, semester);
        assignmentCollection = new ArrayList();
        courseoutcomesurveyresultsCollection = new ArrayList();
        courseoutcomedirectassessmentCollection = new ArrayList();
    }

    public CourseofferingPK getCourseofferingPK() {
        return courseofferingPK;
    }

    public void setCourseofferingPK(CourseofferingPK courseofferingPK) {
        this.courseofferingPK = courseofferingPK;
    }

    public String getInstructor() {
        return instructor;
    }

    public void setInstructor(String instructor) {
        this.instructor = instructor;
    }

    public byte[] getSyllabus() {
        return syllabus;
    }

    public void setSyllabus(byte[] syllabus) {
        this.syllabus = syllabus;
    }

    public byte[] getSchedule() {
        return schedule;
    }

    public void setSchedule(byte[] schedule) {
        this.schedule = schedule;
    }

    public byte[] getLectureNotes() {
        return lectureNotes;
    }

    public void setLectureNotes(byte[] lectureNotes) {
        this.lectureNotes = lectureNotes;
    }

    public String getCourseOutcomeAttainmentTarget() {
        return courseOutcomeAttainmentTarget;
    }

    public void setCourseOutcomeAttainmentTarget(String courseOutcomeAttainmentTarget) {
        this.courseOutcomeAttainmentTarget = courseOutcomeAttainmentTarget;
    }

    public byte[] getEndOfSemesterReport() {
        return endOfSemesterReport;
    }

    public void setEndOfSemesterReport(byte[] endOfSemesterReport) {
        this.endOfSemesterReport = endOfSemesterReport;
    }

    public byte[] getCourseCoordinatorReport() {
        return courseCoordinatorReport;
    }

    public void setCourseCoordinatorReport(byte[] courseCoordinatorReport) {
        this.courseCoordinatorReport = courseCoordinatorReport;
    }

    public byte[] getCICReport() {
        return cICReport;
    }

    public void setCICReport(byte[] cICReport) {
        this.cICReport = cICReport;
    }

    public String getCoursecoordinator() {
        return coursecoordinator;
    }

    public void setCoursecoordinator(String coursecoordinator) {
        this.coursecoordinator = coursecoordinator;
    }

    public String getAltcoursecoordinator() {
        return altcoursecoordinator;
    }

    public void setAltcoursecoordinator(String altcoursecoordinator) {
        this.altcoursecoordinator = altcoursecoordinator;
    }

    @XmlTransient
    public Collection<Courseoutcomedirectassessment> getCourseoutcomedirectassessmentCollection() {
        return courseoutcomedirectassessmentCollection;
    }

    public void setCourseoutcomedirectassessmentCollection(Collection<Courseoutcomedirectassessment> courseoutcomedirectassessmentCollection) {
        this.courseoutcomedirectassessmentCollection = courseoutcomedirectassessmentCollection;
    }

    @XmlTransient
    public Collection<Courseoutcomesurveyresults> getCourseoutcomesurveyresultsCollection() {
        return courseoutcomesurveyresultsCollection;
    }

  
    public Courseinfo getCourseinfo() {
        return courseinfo;
    }

    public void setCourseinfo(Courseinfo courseinfo) {
        this.courseinfo = courseinfo;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (courseofferingPK != null ? courseofferingPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Courseoffering)) {
            return false;
        }
        Courseoffering other = (Courseoffering) object;
        if ((this.courseofferingPK == null && other.courseofferingPK != null) || (this.courseofferingPK != null && !this.courseofferingPK.equals(other.courseofferingPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cse308.entities.Courseoffering[ courseofferingPK=" + courseofferingPK + " ]";
    }
     @Override
    public List<List<GeneralEntity>> getAssociatedClasses() {
        List<List<GeneralEntity>> associatedClasses = new ArrayList();
        associatedClasses.add((List) this.assignmentCollection);
        associatedClasses.add((List) this.courseoutcomedirectassessmentCollection);
        associatedClasses.add((List) this.courseoutcomesurveyresultsCollection);
        return associatedClasses;
    }

    @Override
    public List<GeneralEntity> getAssociatedClass(String associated) {
        if (associated.equals(Assignment.class.getSimpleName())) {
            return (List) this.assignmentCollection;
        }
        if (associated.equals(Courseoutcomedirectassessment.class.getSimpleName())) {
            return (List) this.courseoutcomedirectassessmentCollection;
        }
        if (associated.equals(Courseoutcomesurveyresults.class.getSimpleName())) {
            return (List) this.courseoutcomesurveyresultsCollection;
        }
        if (associated.equals(Courseinfo.class.getSimpleName())) {
            List<GeneralEntity> toReturn = new ArrayList();
            toReturn.add(this.courseinfo);
            return toReturn;
        }
        return null;
    }

    @Override
    public void setWithClass(GeneralTest gt) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void testAddClass(GeneralEntity ge) {
        if (ge instanceof Assignment) {
            this.assignmentCollection.add((Assignment) ge);
        } else if (ge instanceof Courseoutcomedirectassessment) {
            this.courseoutcomedirectassessmentCollection.add((Courseoutcomedirectassessment) ge);
        } else if (ge instanceof Courseoutcomesurveyresults) {
            this.courseoutcomesurveyresultsCollection.add((Courseoutcomesurveyresults) ge);
        }
    }

    @Override
    public void removeClass(GeneralEntity ge) {
        if (ge instanceof Assignment) {
            this.assignmentCollection.remove((Assignment) ge);
        } else if (ge instanceof Courseoutcomedirectassessment) {
            this.courseoutcomedirectassessmentCollection.remove((Courseoutcomedirectassessment) ge);
        } else if (ge instanceof Courseoutcomesurveyresults) {
            this.courseoutcomesurveyresultsCollection.remove((Courseoutcomesurveyresults) ge);
        }
    }

    @Override
    public GeneralEntity findCorrespondingEntity() {
        return this;
    }

    @Override
    public String getIdentifier2() {
        String identifier = this.courseofferingPK.getSemester() + " " + courseofferingPK.getCourse() + " " + courseofferingPK.getSection();
        return identifier;
    }

    @Override
    public boolean equalsEntity(GeneralEntity entity) {
        return this.equals(entity);
    }

    public Collection<Assignment> getAssignmentCollection() {
        return assignmentCollection;
    }

    public void setAssignmentCollection(Collection<Assignment> assignmentCollection) {
        this.assignmentCollection = assignmentCollection;
    }

   

    public void setCourseoutcomesurveyresultsCollection(Collection<Courseoutcomesurveyresults> courseoutcomesurveyresultsCollection) {
        this.courseoutcomesurveyresultsCollection = courseoutcomesurveyresultsCollection;
    }

    @Override
    public Object getPK() {
        return this.courseofferingPK;
    }

   
}
